package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class CollectionDemo {
    public static void main(String[] args) {
        Collection<Point> c = new ArrayList<>();
        c.add(new Point(1, 1));
        c.add(new Point(1, 2));
        c.add(new Point(2, 1));
        System.out.println(c);//Point重写toString方法
        Point p = new Point(1, 2);
        System.out.println("是否包含:" + c.contains(p));//重写hashCode()和equals()方法,内容相同则为true

        c.remove(p);
        System.out.println(c);


        //集合中存放的是元素的引用
        Collection<Point> cc = new ArrayList();
        Point pp = new Point(2, 2);
        cc.add(pp); //将pp添加到cc中-----------将pp的引用装到了cc中
        System.out.println("pp:" + pp); //(2,2)
        System.out.println("cc:" + cc); //[(2,2)]

        pp.setX(200);
        System.out.println("pp:" + pp); //(200,2)
        System.out.println("cc:" + cc); //[(200,2)]


        System.out.println("----------------------------------------------");

        Collection<Fu> c1 = new ArrayList<>();
        c1.add(new Fu("玉皇大帝", 1));
        c1.add(new Fu("太上老君", 2));
        c1.add(new Zi("娃哈哈", 2));
        System.out.println(c1);
        Fu f = new Fu("玉皇大帝", 1);
        Zi z = new Zi("娃哈哈", 2);
        System.out.println("是否包含:" + c1.contains(f));
        System.out.println("是否包含:" + c1.contains(z));
        c1.add(f);
        c1.add(z);
        System.out.println(c1);
        f.setName("假的玉皇大帝");
        z.setName("假的娃哈哈");
        System.out.println(c1);

   /*     Collection<String> c = new ArrayList<>();
        c.add("aaa");
        c.add("bbb");
        c.add("ccc");
        System.out.println(c);
        System.out.println("size:" + c.size());
        System.out.println("是否为空集:" + c.isEmpty());
        System.out.println("----------------------");
        c.clear();
        System.out.println(c);
        System.out.println("size:" + c.size());
        System.out.println("是否为空集:" + c.isEmpty());*/

    }
}
